package dmp.agent;

import java.io.IOException;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.log4j.Logger;

import com.pxene.dmp.useragent.Parser;

public class UrlFilterMap extends Mapper<LongWritable, Text, Text, Text> {
	public static Logger logger1 = Logger.getLogger(Mapper.class);

	// useragent解析器
	private Parser parser = new Parser();

	@Override
	protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
		String line = value.toString();
		String[] words = line.split("\\|");
//		String domain = words[28];
//		String regex = "([^\\.]*)\\.com$|\\.com\\.cn";
//		String rr = URLUtils.regexpExtract(domain, regex);
//		context.write(new Text(domain), new LongWritable(1));
		
		String userAgent = words[26].trim();
		
		
		String str = parser.parseDevice(userAgent).family.trim()+" | "
					+ parser.parseOS(userAgent).family.trim()+" | "
					+parser.parseUserAgent(userAgent).family.trim()+" | "
					+parser.parse(userAgent).device.family.trim()+" | "
					+parser.parse(userAgent).os.family.trim()+" | "
					+parser.parse(userAgent).userAgent.family.trim();

		context.write(new Text(userAgent), new Text(str));
	}
}
